//封装一个存储到本地的方法
//存需要转换成JSON
let set = (key, value) => {
    // console.log(key, value)
    if (key && value) {
        //把value转换成JSON	
        try {
            let json = JSON.stringify(value)
            localStorage.setItem(key, json)
        } catch (e) {
            console.error(e)
        }
    } else {
        console.error('key 和 value必须传递')
    }
}

let get = (key) => {
    let res = localStorage.getItem(key);
    try {
        //取需要转换成正常的对象
        let result = JSON.parse(res)
        return result
    } catch (e) {
        console.log(e)
        return res
    }
}

let rm=(key)=>{
    localStorage.removeItem(key)
} 

export default {
    get,
    set,
    rm,
}